﻿using ChestPainCenterSystem.Areas.ChestPainCenter.Models;
using ChestPainCenterSystem.Code.Bll;
using ChestPainCenterSystem.Core;
using ChestPainCenterSystem.Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ChestPainCenterSystem.Areas.ChestPainCenter.Controllers
{
    public class QualityPointController : BaseController
    {
        static DataTable AllPoint;
        //
        // GET: /ChestPainCenter/QualityPoint/

        public ActionResult Index()
        {
            return View();
        }


        /// <summary>
        /// 诊疗路径列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Search()
        {
            OperateResult resultInfo = PathwayManager.GetQualityPointList();
            if (resultInfo.Body.GetType().Name == "DataTable")
            {
                AllPoint = resultInfo.Body as DataTable;
            }
            var res = new { Rows = resultInfo.Body };
            return JsonDate(res);
        }


        public ActionResult GetAllPoint()
        {
            return JsonDate(AllPoint);
        }

        public ActionResult GetTableColumnList()
        {
            OperateResult resultInfo = PathwayManager.GetTableColumnList();
            return JsonDate(resultInfo.Body as DataTable);
        }

        /// <summary>
        /// 添加/编辑路径
        /// </summary>
        /// <returns></returns>
        public ActionResult Edit(string Id = "0")
        {
            ViewBag.Id = Id;
            return View();
        }
        public ActionResult GetDataById(string Id = null)
        {
            OperateResult resultInfo = PathwayManager.GetQualityPointList(Id);
            return JsonDate(resultInfo.Body);
        }

        /// <summary>
        /// 保存新增或者编辑信息
        /// </summary>
        /// <returns></returns>
        public ActionResult EditSubmit()
        {
            QualityPoint qp = new QualityPoint()
            {
                Id = WebUtils.GetString("Id"),
                Title = WebUtils.GetString("Title"),
                QualityPointTCId = WebUtils.GetString("QualityPointTCId"),
                QualityPointTitle = WebUtils.GetString("QualityPointTitle"),
                QualityPointName = WebUtils.GetString("QualityPointName"),
                QualityPointTableName = WebUtils.GetString("QualityPointTableName"),
                ComparePointTCId = WebUtils.GetString("ComparePointTCId"),
                ComparePointTitle = WebUtils.GetString("ComparePointTitle"),
                ComparePointName = WebUtils.GetString("ComparePointName"),
                ComparePointTableName = WebUtils.GetString("ComparePointTableName"),
                OverTime = WebUtils.GetString("OverTime"),
                Sort = WebUtils.GetString("Sort"),
                Status = WebUtils.GetString("Status")
            };
            OperateResult result = PathwayManager.SaveQualityPoint(qp);
            return Content(result.Body.ToString());
        }

        public ActionResult ChangeStatus()
        {
            string QualityPointTitle = WebUtils.GetString("QualityPointTitle");
            string id = WebUtils.GetString("Id");
            string Status = WebUtils.GetString("Status");
            OperateResult result = PathwayManager.ChangeStatus(id, Status);
            return Content(result.Body.ToString());
        }
    }
}
